package com.zhaoyizhe.mybatis.mapper;

import com.zhaoyizhe.mybatis.model.UserInfo;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @Results(id = "dateBase", value =
            {@Result(column = "delete_flag", property = "deleteFlag"),
                    @Result(column = "create_time", property = "createTime"),
                    @Result(column = "update_time", property = "updateTime"),
            })
    @Select("select * from userinfo")
    List<UserInfo> queryUserInfos();

    @Select("select * from userinfo where id = #{id}")
    List<UserInfo> queryUserInfo(@Param("id") Integer id);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo ( id,username, `password`, age,gender,phone) " +
            "values ( #{userInfo.id}, #{userInfo.username} ,#{userInfo.password}, #{userInfo.age},#{userInfo.gender}," +
            "#{userInfo.phone})")
    Integer insertInfo(@Param("userInfo") UserInfo userInfo);

    @Delete("delete from userinfo where id = #{id}")
    Integer deleteInfo(@Param("id") Integer id);

    @Update("update userinfo set username = #{name} where id = #{id}")
    Integer updateInfo(@Param("name") String name, @Param("id") Integer id);

}
